package cn.cms.dao;


import cn.cms.model.Rank;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.Rename;
import org.jfaster.mango.annotation.SQL;

import java.util.List;

@DB(table = "tbl_rank")
public interface RankDao {

    final static String COLUMNS = "id,col_name,col_poster,col_sort,enabled_pro,plat_form,col_state,col_sub_name,col_video_type,col_rank_num,outside_num,inside_num,robot_flag,rank_status";
    final static String INSERT_COLUMNS = "col_name,col_poster,col_sort,enabled_pro,plat_form,col_state,col_sub_name,col_video_type,col_rank_num,outside_num,inside_num,robot_flag,rank_status";

    @SQL("select  " + COLUMNS +
            " from #table " +
            " where 1=1 " +
            " #if (:t.colName!=null&&:t.colName!='') and col_name like CONCAT('%',:t.colName,'%') #end " +
            " #if (:t.colState!=''&&:t.colState!=null) and col_state = :t.colState #end " +
            " #if (:t.enabledPro!=null&&:t.enabledPro!='') and enabled_pro like CONCAT('%',:t.enabledPro,'%') #end " +
            " order by col_sort asc"
    )
    public List<Rank> getList(PageDao pageDao, @Rename("t") Rank rank);

    @SQL("select " + COLUMNS +
            " from #table" +
            " where 1=1 and id = :id ")
    public Rank getById(@Rename("id") Long id);

    @SQL("insert into #table ( " + INSERT_COLUMNS + " ) values (:t.colName,:t.colPoster,:t.colSort,:t.enabledPro,:t.platForm,:t.colState,:t.colSubName,:t.colVideoType,:t.colRankNum,:t.outsideNum,:t.insideNum,:t.robotFlag,:t.rankStatus)")
    public void save(@Rename("t") Rank rank);

    @SQL("update #table set col_name=:t.colName,col_poster=:t.colPoster,col_sort=:t.colSort,enabled_pro=:t.enabledPro,plat_form=:t.platForm,col_state=:t.colState,col_sub_name=:t.colSubName,col_video_type=:t.colVideoType,col_rank_num=:t.colRankNum,outside_num=:t.outsideNum,inside_num=:t.insideNum,robot_flag=:t.robotFlag,rank_status=:t.rankStatus where id=:t.id")
    public void update(@Rename("t") Rank rank);

    @SQL("delete from #table where id = :t.id")
    public void delete(@Rename("t") Rank rank);

    @SQL("update #table set col_sort = IFNULL(col_sort,0) + 1 where 1=1")
    public void icrSortAll();

    @SQL("select " + COLUMNS +
            " from #table " +
            " where 1=1 order by col_sort asc "
    )
    public List<Rank> getAll();
}
